class NoEndView extends egret.DisplayObjectContainer{

    private _bgMask:egret.Shape; // 背景幕布
    private _contentView:egret.DisplayObjectContainer; // contentView
    private _bg:egret.Bitmap; // 背景
    private _bg2:egret.Bitmap; // 内部背景
    private _sureBtn:egret.DisplayObjectContainer; // 按钮
    private _titleLabel:BaseTextField; // 标题
    private _textLabel:BaseTextField; // 文本
    private _cancleBtn:TbitMap;

    private successCb:()=>{};
    private cancleCb:()=>{};


    constructor(){
        super();
        this.height = GameData.stageH;
        this.width = GameData.stageW;
        this.touchEnabled = true;
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.viewDidLoad, this);
    }

    private viewDidLoad(){
        // 1.幕布
        if(!this.contains(this.bgMask)) this.addChild(this.bgMask);
        // 2.contentView
        if(!this.contains(this.contentView)) this.addChild(this.contentView);
        // 3.bg
        if(!this.contentView.contains(this.bg)) this.contentView.addChild(this.bg);
        // 4.内部背景
        if(!this.contentView.contains(this.bg2)) this.contentView.addChild(this.bg2);
        // 5.内容
        if(!this.contentView.contains(this.textLabel)) this.contentView.addChild(this.textLabel);
        // 6. 确定按钮
        if(!this.contentView.contains(this.sureBtn)) this.contentView.addChild(this.sureBtn);
        // 7. 大标题
        if(!this.contentView.contains(this.titleLabel)) this.contentView.addChild(this.titleLabel);
        // // 8.X
        // if(!this.contentView.contains(this.cancleBtn)){this.contentView.addChild(this.cancleBtn);}

        // 动画
        this.addAnimation();
    }


    public setCallBack(success,cancle):void{
        this.successCb = success;
        this.cancleCb = cancle;
    }


    /*********************************************** private **********************************************************/
    private tapSureAction(){
        Main.removeNoEndView();
    }

    private removeSelf(){
         Main.removeNoEndView();
    }

    private addAnimation(){
        this.contentView.scaleX = 0;
        this.contentView.scaleY = 0;
        egret.Tween.removeTweens(this.contentView);
        egret.Tween.get(this.contentView).to({scaleX:1.0, scaleY:1.0}, 500, egret.Ease.backOut);
    }

    /*********************************************** getter **********************************************************/


    private get textLabel():BaseTextField{
        if(!this._textLabel){
            var textLabel = new BaseTextField();
            textLabel.textColor = 0x8F5B12;
            textLabel.lineSpacing = 15;
            textLabel.width = this.bg2.width ;
            textLabel.bold = true;
            textLabel.x = this.bg2.x;
            textLabel.text = '上期奖励正在结算...\n稍后再来~';
            textLabel.y = this.bg2.y + 80;
            textLabel.textAlign = egret.HorizontalAlign.CENTER;
            textLabel.size = 36;
            this._textLabel = textLabel;
        }
        return this._textLabel;
    }


    private get titleLabel():BaseTextField{
        if(!this._titleLabel){
            var titleLabel = new BaseTextField();
            titleLabel.textColor = 0xFFEC79;
            titleLabel.text = "提示";
            titleLabel.stroke = 2;
            titleLabel.width = this.contentView.width;
            titleLabel.y = 40;
            titleLabel.textAlign = egret.HorizontalAlign.CENTER;
            titleLabel.size = 50;
            titleLabel.bold = true;
            titleLabel.strokeColor = 0x6E3E0E;
            this._titleLabel = titleLabel;
        }
        return this._titleLabel;
    }

    private get sureBtn():egret.DisplayObjectContainer{
        if(!this._sureBtn){

            var btn_container = new egret.DisplayObjectContainer();
            var sureBtn = utils.createBitmapByName('know');
            btn_container.addChild(sureBtn);

            

            btn_container.anchorOffsetX= btn_container.width/2;
            btn_container.anchorOffsetY = btn_container.height/2;
            btn_container.x = this.contentView.width/2;
            btn_container.y = this.bg2.y + this.bg2.height - btn_container.height/2 - 30;
            btn_container.touchEnabled = true;
            btn_container.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tapSureAction, this);
            this._sureBtn = btn_container;
        }
        return this._sureBtn;
    }

    private get bg2():egret.Bitmap{
        if(!this._bg2){
            var bg2 = utils.createBitmapByName('notice_bg', {width:this.contentView.width - 2 * 20});
            bg2.x = 60;
            bg2.y = 140;
            bg2.scale9Grid = new egret.Rectangle(80, 80, 380, 120);
            bg2.height = this.contentView.height - 240;
            bg2.width = (this.contentView.width - 2 * bg2.x);
            this._bg2 = bg2;
        }
        return this._bg2;
    }

    private get bg():egret.Bitmap{
        if(!this._bg){
            var bg = utils.createBitmapByName('friend', {width:this.contentView.width});
            bg.scale9Grid = new egret.Rectangle(0, 146, 600, 91);
            bg.height = this.contentView.height;
            this._bg = bg;
        }
        return this._bg;
    }

    private get contentView():egret.DisplayObjectContainer{
        if(!this._contentView){
            var contentView = new egret.DisplayObjectContainer();
            contentView.touchEnabled = true;
            contentView.width = this.width *0.95;
            contentView.height = 640;
            contentView.anchorOffsetX = contentView.width / 2.0;
            contentView.anchorOffsetY = contentView.height / 2.0;
            contentView.x = this.width / 2.0;
            contentView.y = this.height / 2.0;
            this._contentView = contentView;
        }
        return this._contentView;
    }

    private get bgMask():egret.Shape{
        if(!this._bgMask){
            var bgMask = new egret.Shape();
            bgMask.graphics.beginFill(0x000000, 0.7);
            bgMask.graphics.drawRect(0, 0, this.width, this.height);
            bgMask.graphics.endFill();
            this._bgMask = bgMask;
        }
        return this._bgMask;
    }

    private get cancleBtn():TbitMap{
        if(!this._cancleBtn){
            var btn = utils.createBitmapByName('x',{offsetX:0.5,offsetY:0.5});
            btn.x = this.contentView.width - 40;
            btn.y = 60;
            btn.touchAnimation = true;
            btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.removeSelf,this);
            this._cancleBtn = btn;
        }

        return this._cancleBtn;
    }

}